using DAO;
using DTO;
using System;
using System.Data;

namespace BUS
{
    /// <summary> 
    ///Author: nnamthach@gmail.com 
    /// <summary>
    public class UserControl
    {
        #region Local Variable
        private UserDataAccess _UserDAO;
        #endregion Local Variable
        
        #region Method
        public UserControl()
        {
            _UserDAO = new UserDataAccess();
        }

        public UserInfo Get_User(
            Int64 ID
        , ref string sErr)
        {
            return _UserDAO.Get_User(
            ID
            , ref sErr);
        }

        public UserInfo Get_User_ByUsername(
        String username
    , ref string sErr)
        {
            return _UserDAO.Get_User_ByUsername(username, ref sErr);
        }

         public DataTable Get_User_Test_ByUsername(
          String username
      , ref string sErr)
        {
            return _UserDAO.Get_User_Test_ByUsername(username, ref sErr);
        }

        public DataTable Filter(DataTable dt)
        {
            string expresstion = "CONVERT(SUBSTRING(CONVERT({0},System.String),1,4) +'-'+ SUBSTRING(CONVERT({0},System.String),5,2)+'-'+SUBSTRING(CONVERT({0},System.String),7,2),System.DateTime)";
            if (!dt.Columns.Contains("Regdate_"))
            { dt.Columns.Add("Regdate_", typeof(DateTime), string.Format(expresstion, "Regdate")); }
            if (!dt.Columns.Contains("Birthdate_"))
            { dt.Columns.Add("Birthdate_", typeof(DateTime), string.Format(expresstion, "Birthdate")); }
            return dt;
        }
        public DataTable GetAll_User(ref string sErr)
        {
            return Filter(_UserDAO.GetAll_User(ref sErr));
        }

        public Int32 Add_User(UserInfo obj, ref string sErr)
        {
            return _UserDAO.Add_User(obj, ref sErr);
        }

        public string Update_User(UserInfo obj)
        {
            return _UserDAO.Update_User(obj);
        }

        public string Delete_User(
            Int64 ID
        )
        {
            return _UserDAO.Delete_User(
            ID
            );
        }
        public Boolean IsExist_User(
            Int64 ID
        )
        {
            return _UserDAO.IsExist_User(
            ID
            );
        }

        /*  public string Delete_User(String arrID)
          {
              string kq = "";
              string[] arrStrID = arrID.Split(',');
              foreach (string strID in arrStrID)
              {
                  if (strID != "")
                  {
                      int ID = Convert.ToInt32(strID);
                      kq += _UserDAO.Delete_User(ID);
                  }
              }
              return kq;
          } */

        public DataTableCollection Get_Page(UserInfo obj, string orderBy, int pageIndex, int pageSize, ref String sErr)
        {
            return _UserDAO.Get_Page(obj, orderBy, pageIndex, pageSize, ref sErr);
        }

        public DataTable Search(String columnName, String columnValue, String condition, ref String sErr)
        {
            return _UserDAO.Search(columnName, columnValue, condition, ref  sErr);
        }

        #endregion Method

    }
}
